package cn.koala.key.firstmaintain.service.impl;

import cn.koala.key.api.FirstMaintainCardApi;
import cn.koala.key.common.feign.FeignUtils;
import cn.koala.key.common.utils.BaseEntityUtil;
import cn.koala.key.firstmaintain.entity.dto.FirstMaintainCardDeductParamDTO;
import cn.koala.key.firstmaintain.entity.dto.FirstMaintainCardSearchModel;
import cn.koala.key.firstmaintain.entity.dto.FirstMaintainCardTypeModifyDTO;
import cn.koala.key.firstmaintain.entity.vo.FirstMaintainCardSearchParamVO;
import cn.koala.key.firstmaintain.entity.vo.FirstMaintainCardSearchResultVO;
import cn.koala.key.firstmaintain.service.FirstMaintainCardService;
import cn.seed.common.core.Result;
import cn.seed.common.core.ResultList;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author liutao
 * @date 2021/1/26
 */
@Service
public class FirstMaintainCardServiceImpl implements FirstMaintainCardService {

    @Override
    public Result<?> batchReceive(List<String> vinNoList, String oprNo, String oprName) {
        return FeignUtils.getHttpApi(FirstMaintainCardApi.class).batchReceive(vinNoList, oprNo, oprName);
    }

    @Override
    public Result<?> batchDeductCount(List<FirstMaintainCardDeductParamDTO> paramDTOList) {
        return FeignUtils.getHttpApi(FirstMaintainCardApi.class).batchDeductCount(paramDTOList);
    }

    @Override
    public Result<?> batchModifyCardType(List<FirstMaintainCardTypeModifyDTO> paramDTOList) {
        return FeignUtils.getHttpApi(FirstMaintainCardApi.class).batchModifyCardType(paramDTOList);
    }

    @Override
    public Result<ResultList<FirstMaintainCardSearchResultVO>> searchByCondition(FirstMaintainCardSearchParamVO paramVO) {
        return FeignUtils.getHttpApi(FirstMaintainCardApi.class).searchByCondition(paramVO);
    }

    @Override
    public List<FirstMaintainCardSearchModel> searchPrint(FirstMaintainCardSearchParamVO paramVO) {
        Result<ResultList<FirstMaintainCardSearchResultVO>> resultListResult = FeignUtils.getHttpApi(FirstMaintainCardApi.class).searchByCondition(paramVO);
        return convertFirstMaintainCardSearchModel(resultListResult.getResult().getData());
    }

    private List<FirstMaintainCardSearchModel> convertFirstMaintainCardSearchModel(List<FirstMaintainCardSearchResultVO> firstMaintainCardSearchResultList) {
        List<FirstMaintainCardSearchModel> models = BaseEntityUtil.toList(firstMaintainCardSearchResultList, firstMaintainCardSearchResultVO -> {
            FirstMaintainCardSearchModel model = new FirstMaintainCardSearchModel();
            model.setVinNo(firstMaintainCardSearchResultVO.getVinNo());
            model.setBrandSeriesName(firstMaintainCardSearchResultVO.getBrandName().concat(firstMaintainCardSearchResultVO.getSeriesName()));
            model.setTotalCount(firstMaintainCardSearchResultVO.getTotalCount());
            model.setRemainCount(firstMaintainCardSearchResultVO.getRemainCount());
            model.setTypeName(firstMaintainCardSearchResultVO.getTypeName());
            model.setStatusName(firstMaintainCardSearchResultVO.getStatusName());
            model.setGmtCreate(firstMaintainCardSearchResultVO.getGmtCreate());
            model.setReceiveTime(firstMaintainCardSearchResultVO.getReceiveTime());
            model.setOprName(firstMaintainCardSearchResultVO.getOprNo().concat(firstMaintainCardSearchResultVO.getOprName()));
            return model;
        });
        return models;
    }
}
